package com.sh.data.engine.application.model.request.integration;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.List;

@Data
@Schema
public class FlinkDataSyncTaskRequest {

    /**
     * 主键
     */
    @Schema(title = "任务id", description = "空为新增 不空为保存")
    private Long id;

    /**
     * 任务名称
     */
    @Schema(description = "任务名称")
    @NotBlank(message = "任务名称不能为空")
    @Length(min = 2, max = 64, message = "名称长度为2-64个字符")
    @Pattern(regexp = "[a-zA-Z0-9_\\u4e00-\\u9fa5]+", message = "名称支持中文、字母、数字、下划线")
    private String taskName;

    @Schema(description = "目录id")
    @NotBlank(message = "所在目录id不能为空")
    private Long dirId;

    /**
     * 任务描述
     */
    @Schema(description = "任务描述")
    @Length(max = 128, message = "描述长度不能超过128个字符")
    private String remark;

    /**
     * 来源数据源id
     */
    @Schema(description = "来源数据源id")
    private Long sourceDsId;

    /**
     * 来源数据源类型
     */
    @Schema(description = "来源数据源类型")
    private String sourceDsType;

    /**
     * 目标数据源id
     */
    @Schema(description = "目标数据源id")
    private Long targetDsId;

    /**
     * 来源数据源类型
     */
    @Schema(description = "目标数据源类型")
    private String targetDsType;

    @Schema(description = "来源表表名或topic")
    private String sourceTableOrTopic;

    @Schema(description = "目标表表名或topic")
    private String targetTableOrTopic;

    @Schema(description = "字段映射")
    private List<FieldMapping> fieldMappings;

    @Schema(description = "0-insert ,1-update,2-delete")
    private List<Integer> operatorMode;

    @Schema(description = "cdc模式只有mysql和oracle存在该配置,0-默认  1-latest-offset  ")
    private Integer start;

    @Schema(description = "同步前是否删除历史记录，0-是，1否")
    private Integer syncDeleteFlag;

    @Schema(
        description =
            "当start为 0时 startValue为null,start为 1时 startValues为时间戳 ,start为2时可startValue 为文件名，start为3时为null")
    private String startValue;

    @Schema(description = "是否使用js脚本解析 0-默认 1-自定义 2-velocity")
    private Integer useJsFlag;

    @Schema(description = "javaScript脚本")
    private String jsContent;

    @Schema(description = "kafka/mqtt 变量关系")
    private List<FieldExpresses> fieldExpressRequests;

    @Schema(description = "前端展示使用参数")
    private List<String> tableData;

    @Schema(description = "来源为oracle、pg schema")
    private String sourceSchema;

    @Schema(description = "目标为orcle、pg schema")
    private String targetSchema;

    @Data
    @Schema(name = "FlinkDataSyncTaskRequest-FieldMapping")
    public static class FieldMapping {

        @Schema(description = "变量表达式")
        private String sourceFieldExpress;

        @Schema(description = "来源字段名，结果变量名：来源为kafka、mqtt时")
        private String sourceField;

        @Schema(description = "来源字段类型")
        private String sourceFieldType;

        @Schema(description = "来源字段是否是主键")
        private Integer isSourceFieldPk;

        @Schema(description = "来源字段是否是分区字段")
        private Integer isSourcePartition;

        @Schema(description = "目标字段名")
        private String targetField;

        @Schema(description = "目标字段类型")
        private String targetFieldType;

        @Schema(description = "目标字段是否是主键")
        private Integer isTargetFieldPk;

        @Schema(description = "目标字段是否是分区字段")
        private Integer isTargetPartition;

        @Schema(description = "目标字段是否是标签字段")
        private Integer isTargetTag;
    }

    @Data
    @Schema
    public static class FieldExpresses {
        @Schema(description = "变量名")
        private String fieldName;

        @Schema(description = "变量表达式")
        private String fieldExpress;
    }
}
